/**
 * 根据起始元素获取起始坐标
 */

function coordinate (startElement, endElement, position, ) {
  if (!startElement || !endElement) {
  // console.error('startElement & endElement is undefined or not render completed.')
  return
  }

  const startCoordinate = {
    x: startElement.offsetLeft,
    y: startElement.offsetTop,
    width: startElement.offsetWidth,
    height: startElement.offsetHeight
  }
  const endCoordinate = {
    x: endElement.offsetLeft,
    y: endElement.offsetTop,
    width: endElement.offsetWidth,
    height: endElement.offsetHeight
  }
  const result = {start: {}, end: {}}

  // 没有计算半径

  result.start = {
    x: startCoordinate.x + startCoordinate.width / 2,
    y: startCoordinate.y + startCoordinate.height / 2
  }

  switch (position) {
    case 'leftTop':
      result.end = {
        x: endCoordinate.x + endCoordinate.width / 3,
        y: endCoordinate.y + endCoordinate.height
      }
      break;
    case 'top':
      result.end = {
        x: endCoordinate.x + endCoordinate.width / 3,
        y: endCoordinate.y + endCoordinate.height
      }
      break;
    case 'rightTop':
      result.end = {
        x: endCoordinate.x + endCoordinate.width / 3,
        y: endCoordinate.y + endCoordinate.height
      }
      break;
    case 'left':
      result.end = {
        x: endCoordinate.x + endCoordinate.width,
        y: endCoordinate.y + endCoordinate.height / 3
      }
      break; 
    case 'right':
      result.end = {
        x: endCoordinate.x,
        y: endCoordinate.y + endCoordinate.height / 3
      }
      break;
    case 'leftBottom':
      result.end = {
        x: endCoordinate.x + endCoordinate.width /3,
        y: endCoordinate.y
      }
      break;
    case 'bottom':
      result.end = {
        x: endCoordinate.x + endCoordinate.width / 3,
        y: endCoordinate.y
      }
      break;
    case 'rightBottom':
      result.end = {
        x: endCoordinate.x  + endCoordinate.width / 3,
        y: endCoordinate.y
      }
      break;
  }

  return result
}

export default coordinate